#!/bin/sh
num2=0
#ping -c 3 -w 3  192.168.3.23 > /mnt/mtd/ping.log
insmod /opt/xag/net/g_ether.ko
ifconfig lo 127.0.0.1
ifconfig usb0 192.168.3.10 mtu 500 up
r=$RANDOM

while true
do
ping -c 3 -w 3  192.168.3.23 >> /dev/null
if [ $? -eq 0 ];then
        #echo "usb0 is ready"
        sleep 8
else
        echo "usb0 is not ready"
        rmmod g_ether

        insmod /opt/xag/net/g_ether.ko
        ifconfig lo 127.0.0.1
        ifconfig usb0 192.168.3.10 mtu 500 up
        if [ $num2 -gt 0 ] ; then
                echo "usb0 is not ready"
                current_time=$(date "+%Y%m%d-%H%M%S")
                echo $current_time > /mnt/mtd/error-$r-$current_time.log
                dmesg >> /mnt/mtd/error-$r-$current_time.log
                echo "flase" > /mnt/mtd/flag_mark
        fi
        num2=`expr $num2 + 1`
        echo $num2
        sleep 5
fi
done
